﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Manager_System
{
    public partial class intoWH_product : Form
    {
        string name = "";
        string Price = "";//原价格
        string Id = "";
        string Weight = "";//原有重量
        main_form form2;
        public intoWH_product(string weight,string id,string price,string sum,main_form form)
        {
            main_form form1 = form;
            Id = id;
            Price = price;
            Weight = weight;
            name = sum;
            //this.name_tb.Text=
            InitializeComponent();
            this.after_tb.Text = Weight.ToString();
            this.name_tb.Text = name;
            this.id_tb.Text = Id;
           
            this.price_tb.Text = price;
            form2 = form1;
        }

        private void intoWH_Load(object sender, EventArgs e)
        {

        }

        private void weight_tb_TextChanged(object sender, EventArgs e)
        {
            if (this.after_tb.Text != null && this.weight_tb.Text != null && !this.after_tb.Text.Equals("") && !this.weight_tb.Text.Equals(""))
            {
                after_tb.Text = Weight;
                double weight = double.Parse(this.weight_tb.Text);
                double after = double.Parse(this.after_tb.Text);

                after = weight + after;
                this.after_tb.Text = after.ToString();
            }
            else
            {
                this.after_tb.Text = Weight;
            }
        }

        private void confirm_bt_Click(object sender, EventArgs e)
        {
            int p = int.Parse(Price);
            int w = int.Parse(Weight);
            int sum = p * w;
            double p_now = double.Parse(this.price_tb.Text);
            double w_now = double.Parse(this.weight_tb.Text);
            double sum_now = p_now * w_now;
            sum_now = sum + sum_now;
            p_now = sum_now / (double.Parse(after_tb.Text));
            form2.recive(p_now.ToString(), after_tb.Text.ToString());
            string sql = "update T_WH_product set Weight="+after_tb.Text+",Price="+p_now+" where ID="+this.id_tb.Text+"";
            DBhelp db = new DBhelp();
            int rs=db.update(sql);
            db.close();
            if (rs == 1)
            {
                MessageBox.Show("修改成功！");
                form2.recive(p_now.ToString(), after_tb.Text.ToString());
                this.Close();
            }
            else
            {
                MessageBox.Show("修改失败！");
            }
        }

        private void close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
